package org.essilab.analyzer.Configuration;

import java.io.FileReader;
import java.util.Properties;

/**
 * This class is used to read property files.
 *
 * @author Mohamed-Amine Chouchene, Ahcène Idinarere, Vincent Nock, Alain
 * Janin-Manificat
 */
public class Config {

    static boolean init = false;
    static Properties props = new Properties();

    /**
     * Load a property file. Swith Config#init to true if the load success.
     *
     * @param filename - path of the property file to load.
     */
    public static void setFile(String filename) {
        try {
            props.load(new FileReader(filename));
            init = true;
        } catch (Exception e) {
            init = false;
            e.printStackTrace();
        }

    }

    /**
     * Return the property value of the given key.
     *
     * @param key String - key to look for in previously loaded property file.
     * @return String - If the key exist and a property file is loaded, return
     * the property value else return null.
     */
    public static String get(String key) {
        if (init) {
            return props.getProperty(key);
        }
        return null;
    }
}
